package components;

import dao.PetDAO;
import entity.Appointment;
import java.util.Comparator;
import java.util.TreeSet;
import javax.persistence.Persistence;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class ComponentFactory {
    
    public static void attachVerifier(String message, JTextField component) {
        TextFieldVerifier textFieldVerifier = new TextFieldVerifier(message, component);
        component.setInputVerifier(textFieldVerifier);
        component.addActionListener(textFieldVerifier);
    }
    
    public static void attachVerifier(String message, JComboBox component) {
        ComboBoxVerifier comboBoxVerifier = new ComboBoxVerifier(message, component);
        component.setInputVerifier(comboBoxVerifier);
        component.addActionListener(comboBoxVerifier);
    }
    
    public static Appointment newAppointmentDialog(JFrame parent) {
        DAppointmentCreation appointmentCreation = new DAppointmentCreation(parent, true);
        PetDAO petDAO = new PetDAO(Persistence.createEntityManagerFactory("HPVA"));
        TreeSet ts = new TreeSet(new Comparator<Object>() {

            @Override
            public int compare(Object o1, Object o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        ts.addAll(petDAO.findEntities());
        appointmentCreation.setPets(ts);
        appointmentCreation.setVisible(true);
        return appointmentCreation.getAppointment();
    }

}
